package com.ciko.code.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.mywork.WorkUIKit;


public class PerferencesUtil {
    private SharedPreferences preferences;
    private Editor editor;
    private static PerferencesUtil instance;
    private static String APPROVER_LAST_TIME_STAMP = "approver_last_time_stamp";
    private static String                  CONTACT_LAST_TIME_STAMP          = "contact_last_time_stamp";
    private static String                  APPROVE_SELECT_LAST_TIME_STAMP          = "approve_select_last_time_stamp";
    private static String LAST_LOGIN_USER = "last_login_user";

    private PerferencesUtil(Context context) {
        String fileName = "Perferences";
        preferences = context.getSharedPreferences(fileName, Context.MODE_PRIVATE);
        editor = preferences.edit();
    }

    public static PerferencesUtil getInstance(Context context) {
        if (instance == null) {
            instance = new PerferencesUtil(context);
        }
        return instance;
    }

    public SharedPreferences getSharedPreferences() {
        return preferences;
    }

    //请假的选择审批人调用接口时间戳
    public long getApproveContactLastTimeStamp() {
        return preferences.getLong(APPROVER_LAST_TIME_STAMP + WorkUIKit.getUserId(), 0L);
    }

    public void setApproveContactLastTimeStamp(long value) {
        editor.putLong(APPROVER_LAST_TIME_STAMP + WorkUIKit.getUserId(), value);
        editor.commit();
    }
    //通讯录的选择审批人调用接口时间戳
    public long getContactLastTimeStamp() {
        return preferences.getLong(CONTACT_LAST_TIME_STAMP + WorkUIKit.getUserId(), 0L);
    }


    public void setContactLastTimeStamp(long value) {
        editor.putLong(CONTACT_LAST_TIME_STAMP + WorkUIKit.getUserId(), value);
        editor.commit();
    }

    //因公外出的选择审批人调用接口时间戳
    public long getApproveSelectLastTimeStamp() {
        return preferences.getLong(APPROVE_SELECT_LAST_TIME_STAMP + WorkUIKit.getUserId(), 0L);
    }

    public void setApproveSelectLastTimeStamp(long value) {
        editor.putLong(APPROVE_SELECT_LAST_TIME_STAMP + WorkUIKit.getUserId(), value);
        editor.commit();
    }

    //获取上一个登录用户id
    public String getLastLoginUser() {
        return preferences.getString(LAST_LOGIN_USER, "");
    }
    public void setLastLoginUser(String value) {
        editor.putString(LAST_LOGIN_USER, value);
        editor.commit();
    }
    /**
     * 清空所有数据
     */
    public void clearAllData() {
        editor.clear();
        editor.commit();
    }
}
